import React from 'react';
import Mixins from '@/components/Common/mixin';
import connectFn from '@/utils/connectFn';
import CreateCard from '@/components/CreateCard';
import CreateForm from '@/components/CreateForm';
import CreateTable from '@/components/CreateTable';
import CreateModal from '@/components/CreateModal';
import constant from '@/const';
import { StateType } from '@/common-typings';
import { types } from '@/utils/utils';
import { getFormData } from '@/pages/riskControl/memberList/config';

const { SUCCESS_CODE } = constant;

@connectFn([], ['getManageUserLevelList'])
class MemberList extends Mixins {
  state = {
    searchLoading: false,
    userLevelList: [],
  };

  componentDidMount(): void {
    this.requestUserLevel();
  }

  /**
   * 查询列表
   * @param params
   * @param key
   */
  requestList = (params = {}, key?: string) => {
    console.log(params);
  };

  /**
   * 查询层级
   */
  requestUserLevel = () => {
    const { getManageUserLevelList } = this.props;
    getManageUserLevelList({}).then((res: StateType) => {
      const { code, data } = res;
      if (code === SUCCESS_CODE && data && types(data) === 'array') {
        const userLevelList: any[] = [];
        data.forEach((item: StateType) => {
          userLevelList.push({
            label: item.name,
            value: item.levelId,
          });
        });
        this.changeState({ userLevelList });
      }
    });
  };

  render() {
    return (
      <CreateCard>
        <CreateForm
          formConfig={getFormData(this)}
          ref={ref => {
            this.bindFormRef = ref;
          }}
        />
      </CreateCard>
    );
  }
}

export default MemberList;
